//
//  MASTableViewProfieCell.m
//  MasonryExample
//
//  Created by 山刘 on 2020/6/11.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "MASTableViewProfieCell.h"

@interface MASTableViewProfieCell()
@property (strong, nonatomic) MASConstraint* masHeight;
@end


@implementation MASTableViewProfieCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.headImageView = [LayoutUtils createView];
        self.headImageView.layer.cornerRadius = 30;
        self.headImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.headImageView];
        [self.headImageView makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@60);
            make.height.equalTo(@60).priorityLow();
            make.left.top.equalTo(kPadding);
            make.bottom.lessThanOrEqualTo(kPadding);
        }];
        [self.headImageView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        
        self.titleLabel = [LayoutUtils fixedLabelWithText:@""];
        [self.contentView addSubview:self.titleLabel];
        self.titleLabel.numberOfLines = 1;
        [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(kPadding);
            make.left.equalTo(self.headImageView.mas_right).insets(kPadding);
            make.right.lessThanOrEqualTo(kPadding);
        }];
        
        
        self.descabel = [LayoutUtils fixedLabelWithText:@""];
        self.descabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.descabel];
        [self.descabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImageView.mas_right).insets(kPadding);
            make.top.equalTo(self.headImageView.mas_centerY);
            make.right.lessThanOrEqualTo(kPadding);
            
            //make.bottom.equalTo(kPadding);
            self.masHeight = make.height.lessThanOrEqualTo(@100);
            //make.bottom.greaterThanOrEqualTo(self.headImageView);
            make.bottom.lessThanOrEqualTo(kPadding);
        }];
        
    }
    return self;
}
-(void)updateData{
    self.titleLabel.text = self.cellData.content;
    self.descabel.text = self.cellData.content;
    if (self.cellData.isExpended) {
        NSLog(@"==1==");
        [self.masHeight uninstall];
        self.descabel.numberOfLines = 0;
    }else{
        NSLog(@"==2==");
        [self.masHeight install];
        self.descabel.numberOfLines = 3;
    }
    
    [super updateData];
}

-(void)updateConstraints{
    [super updateConstraints];
}
@end
